package com.hzc.springchan.command.verlocitygeneric;

import com.hzc.springchan.enums.PrivError;
import com.hzc.springchan.bean.exception.CException;

/**
 * 模板生成命令执行类
 * @author chen990627
 * @date 2022/10/11
 */
public class VelocityGenericInvoker {

    private String className;

    private IGenericCommand command;

    private boolean check;

    public VelocityGenericInvoker(String className, IGenericCommand command) {
        this.className = className;
        this.command = command;
        this.check = true;
    }

    public VelocityGenericInvoker update(IGenericCommand command) {

        if (check) {
            throw new CException(PrivError.GENERIC_CHECK_STATUS_ERROR);
        }

        this.command = command;
        this.check = true;
        return this;
    }

    public VelocityGenericInvoker execute() {

        if (!check) {
            throw new CException(PrivError.GENERIC_CHECK_STATUS_ERROR);
        }

        check = false;
        this.command.execute(className);
        return this;
    }
}
